home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / src / p4char.c < prev    next >
Text File  |  1993-12-06  |  5KB  |  175 lines

  1. /**
  2.  ** P4CHAR.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "p4.h"
  25. #include "memfill.h"
  26. #include "memcopy.h"
  27. #include "bitdraw.h"
  28.  
  29. void _GrP4DrawChar(long a,int wdt,int hgt,char far *bits,int fg,int bg)
  30. {
  31.     char far *bb;
  32.     pixptr pp,p = P_ADDRESS(CURC,a);
  33.     int fgop = C_OPER(fg);
  34.     int bgop = C_OPER(bg);
  35.     int shift  = P_OFFSET(a);
  36.     int drawfg = _GrP4DrawTable[fgop] ^ (fg &= C_SIGNIF);
  37.     int drawbg = _GrP4DrawTable[bgop] ^ (bg &= C_SIGNIF);
  38.     int offset = CURC->gc_lineoffset;
  39.     int bitwdt = (wdt + 7) >> 3;
  40.     int plane,mask,hh;
  41.  
  42.     if((wdt <= 0) || (hgt <= 0)) return;
  43.     if((drawfg | drawbg) == 0) return;
  44.     if((mask = P_OFFSET((int)a + wdt)) != 0) {
  45.         wdt -= mask;
  46.         mask = (unsigned char)(0xff00 >> mask);
  47.     }
  48.     wdt = (wdt + 7) >> 3;
  49.     _ClrDir();
  50.     if(CURC->gc_onscreen) {
  51.         if(drawbg) {
  52.         pp = p;
  53.         _SetVideoColor(bg,bgop);
  54.         if(fgop == C_SET) {
  55.             int wdt2 = wdt;
  56.             int msk2 = mask;
  57.             if(shift) {
  58.             int lmask = 0xff >> shift;
  59.             if(--wdt2 < 0) { lmask &= msk2; msk2 = 0; }
  60.             _SetVGAWriteMask(lmask);
  61.             _ColSetXorB(VLEFT,pp,offset,0,hgt);
  62.             pp++;
  63.             }
  64.             if(wdt2 > 0) {
  65.             _SetVGAWriteMask(0xff);
  66.             plane = offset - wdt2;
  67.             if(bgop == C_SET)
  68.                 _BlkSetB(VBODY,pp,plane,0,wdt2,hgt);
  69.             else {
  70.                 _SaveDS();
  71.                 _BlkCpyB(VBODY,pp,plane,pp,plane,wdt2,hgt);
  72.                 _RestoreDS();
  73.             }
  74.             pp += wdt2;
  75.             }
  76.             if(msk2) {
  77.             _SetVGAWriteMask(msk2);
  78.             _ColSetXorB(VRIGHT,pp,offset,0,hgt);
  79.             }
  80.         }
  81.         else if(_GrAdapterType == GR_VGA) {
  82.             _SetVGAWriteMode(8+3);
  83.             _SetVGAWriteMask(0xff);
  84.             _SetVGADontCareRegister(0x00);
  85.             _SaveDS();
  86.             for(bb = bits,hh = hgt; --hh >= 0; ) {
  87.             _CharBGRowVGA(pp,bb,wdt,shift,mask);
  88.             pp += offset;
  89.             bb += bitwdt;
  90.             }
  91.             _RestoreDS();
  92.             _SetVGAWriteMode(0);
  93.         }
  94.         else {
  95.             _SetVGAWriteMask(0xff);
  96.             _SaveDS();
  97.             for(bb = bits,hh = hgt; --hh >= 0; ) {
  98.             _CharBGRowEGA(pp,bb,wdt,shift,mask);
  99.             pp += offset;
  100.             bb += bitwdt;
  101.             }
  102.             _RestoreDS();
  103.         }
  104.         }
  105.         if(drawfg) {
  106.         _SetVideoColor(fg,fgop);
  107.         _SetVGAWriteMask(0xff);
  108.         if(_GrAdapterType == GR_VGA) {
  109.             _SetVGAWriteMode(8+3);
  110.             _SetVGADontCareRegister(0x00);
  111.             _SaveDS();
  112.             while(--hgt >= 0) {
  113.             _CharFGRowVGA(p,bits,wdt,shift,mask);
  114.             p += offset;
  115.             bits += bitwdt;
  116.             }
  117.             _RestoreDS();
  118.             _SetVGAWriteMode(0);
  119.         }
  120.         else {
  121.             _SaveDS();
  122.             while(--hgt >= 0) {
  123.             _CharFGRowEGA(p,bits,wdt,shift,mask);
  124.             p += offset;
  125.             bits += bitwdt;
  126.             }
  127.             _RestoreDS();
  128.         }
  129.         }
  130.         return;
  131.     }
  132.     fgop <<= 1;
  133.     bgop <<= 2;
  134.     for(plane = 4; --plane >= 0; fg >>= 1,bg >>= 1) {
  135.         _SaveDS();
  136.         if(drawfg) for(pp = p,bb = bits,hh = hgt; --hh >= 0; ) {
  137.         switch(fgop | (fg & 1)) {
  138.           case C_XOR2+1:
  139.             _CharFGRowXor(pp,bb,wdt,shift,mask);
  140.             break;
  141.           case C_OR2+1:
  142.           case C_SET2+1:
  143.             _CharFGRowOr(pp,bb,wdt,shift,mask);
  144.             break;
  145.           case C_AND2+0:
  146.           case C_SET2+0:
  147.             _CharFGRowAnd(pp,bb,wdt,shift,mask);
  148.             break;
  149.         }
  150.         pp += offset;
  151.         bb += bitwdt;
  152.         }
  153.         if(drawbg) for(pp = p,bb = bits,hh = hgt; --hh >= 0; ) {
  154.         switch(fgop | (fg & 1)) {
  155.           case C_XOR2+1:
  156.             _CharBGRowXor(pp,bb,wdt,shift,mask);
  157.             break;
  158.           case C_OR2+1:
  159.           case C_SET2+1:
  160.             _CharBGRowOr(pp,bb,wdt,shift,mask);
  161.             break;
  162.           case C_AND2+0:
  163.           case C_SET2+0:
  164.             _CharBGRowAnd(pp,bb,wdt,shift,mask);
  165.             break;
  166.         }
  167.         pp += offset;
  168.         bb += bitwdt;
  169.         }
  170.         _RestoreDS();
  171.         p = (pixptr)((long)p + CURC->gc_planeoffset);
  172.     }
  173. }
  174.  
  175.